﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Admin_ShopDeliverType : Admin, IRequiresSessionState
{
    private Shop_DeliverType _shop_deliverType = null;
    private UserBll _user = null;
    private string wherestr = "";
    private string linkhead = "";
    private IDbDataParameter[] param;
    private ArrayList al = new ArrayList();
    private bool tag = true;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Shop_DeliverType shop_deliverType
    {
        get
        {
            Shop_DeliverType shop_deliverType;
            if (this._shop_deliverType == null)
            {
                this._shop_deliverType = new Shop_DeliverType(this.conn);
                shop_deliverType = this._shop_deliverType;
            }
            else
            {
                shop_deliverType = this._shop_deliverType;
            }
            return shop_deliverType;
        }
    }
    protected UserBll user
    {
        get
        {
            UserBll user;
            if (this._user == null)
            {
                this._user = new UserBll(this.conn);
                user = this._user;
            }
            else
            {
                user = this._user;
            }
            return user;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(31))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "PayType");
            base.WriteRightErrMsg();
        }
        if (!base.IsPostBack)
        {
            this.BindList();
        }
    }
    protected void BindList()
    {
        this.QueryString();
        int num = Fetch.GetID("page");
        if (num <= 0)
        {
            num = 1;
        }
        int pageSize = this.GridView1.PageSize;
        if (this.al.Count > 0)
        {
            this.param = new IDbDataParameter[this.al.Count];
            this.al.CopyTo(this.param, 0);
        }
        if (this.param != null)
        {
            this.GridView1.DataSource = this.shop_deliverType.GetAllDeliverType(num, pageSize, this.wherestr, "", this.param);
        }
        else
        {
            this.GridView1.DataSource = this.shop_deliverType.GetAllDeliverType(num, pageSize, this.wherestr, "");
        }
        this.GridView1.DataBind();
        this.PagePanel.Text = this.shop_deliverType.GetPagePanel(this.linkhead);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        bool flag = base.admin.CheckAdminPower(31);
        bool flag2 = base.admin.CheckAdminPower(31);
        bool flag3 = base.admin.CheckAdminPower(31);
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            if (!flag2)
            {
                ((LinkButton)e.Row.FindControl("cl")).Enabled = false;
            }
            if (!flag2)
            {
                e.Row.Cells[6].Enabled = false;
            }
            if (!flag3)
            {
                e.Row.Cells[7].Enabled = false;
            }
        }
    }
    protected void Delete_ButtonClick(object sender, CommandEventArgs e)
    {
        if (base.admin.CheckAdminPower(31))
        {
            int num = 0;
            try
            {
                num = Convert.ToInt32(e.CommandArgument.ToString());
            }
            catch
            {
                this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
            }
            if (num > 0)
            {
                if (this.shop_deliverType.DeleteDeliver(num))
                {
                    this.BindList();
                }
                else
                {
                    this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
                }
            }
            else
            {
                this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
            }
        }
        else
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "DeliverType");
            base.WriteRightErrMsg();
        }
    }
    protected void QueryString()
    {
        string text;
        if (Fetch.Get("userName") != string.Empty && this.tag)
        {
            text = (this.TextBox1.Text = Fetch.Get("userName"));
        }
        else
        {
            text = this.TextBox1.Text;
        }
        if (text != string.Empty)
        {
            this.wherestr += "and UserID in(select UserID From [HL_User] Where UserName like '%' + @UserName + '%') ";
            this.al.Add(this.conn.CreateParameter("@UserName", DbType.String, text));
            this.linkhead = this.linkhead + "&userName=" + base.Server.UrlEncode(text);
        }
        string text2 = this.txtDeliverTypeName.Text;
        if (text2 != "")
        {
            this.wherestr += "and TypeName like '%'+@TypeName+'%'";
            this.al.Add(this.conn.CreateParameter("@TypeName", DbType.String, text2));
        }
        if (this.wherestr != string.Empty)
        {
            this.wherestr = this.wherestr.Substring(3);
            this.wherestr = "where" + this.wherestr;
        }
    }
    protected void btn_cearchType_Click(object sender, EventArgs e)
    {
        this.tag = false;
        this.BindList();
    }
    protected void lb_enable_Command(object sender, CommandEventArgs e)
    {
        if (base.admin.CheckAdminPower(31))
        {
            int num = 0;
            try
            {
                num = Convert.ToInt32(e.CommandArgument.ToString());
            }
            catch
            {
                this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
            }
            if (num > 0)
            {
                DataTable deliverTypeByID = this.shop_deliverType.GetDeliverTypeByID(num);
                bool flag = (bool)deliverTypeByID.Rows[0]["IsDisabled"];
                if (this.shop_deliverType.SetDisenabled(!flag, num))
                {
                    this.BindList();
                }
                else
                {
                    this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
                }
            }
            else
            {
                this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
            }
        }
        else
        {
            base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "DeliverType");
            base.WriteRightErrMsg();
        }
    }
}
